package cn.rokhdelar.umbrsapi.management.service;

import cn.rokhdelar.umbrsapi.management.entity.SysPermission;
import cn.rokhdelar.umbrsapi.management.repository.SysPermissionRepo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class SysPermissionService {
    private final SysPermissionRepo sysPermissionRepo;

    public SysPermissionService(SysPermissionRepo sysPermissionRepo) {
        this.sysPermissionRepo = sysPermissionRepo;
    }

    public Page<SysPermission> list(String name, Pageable pageable) {
        return sysPermissionRepo.findAllByNameContaining(name, pageable);
    }

    public SysPermission get(Long id) {
        return sysPermissionRepo.findById(id).orElse(null);
    }

    public SysPermission save(SysPermission sysPermission) {
        return sysPermissionRepo.save(sysPermission);
    }

    public void delete(Long id) {
        sysPermissionRepo.deleteById(id);
    }
}
